#include <errno.h>
#include "ourhdr.h"

static void pr_sysconf(char *, int);
static void pr_pathconf(char *, char *, int);

int
main(int argc, char *argv[])
{
	if (argc != 2) {
		err_quit("usage: a.out <dirname>");
	}
	
	pr_sysconf("ARG_MAX = ", _SC_ARG_MAX);

	pr_pathconf("MAX_CANON = ", "/dev/tty", _PC_MAX_CANON);
}

static void
pr_sysconf(char *mesg, int name)
{
	long val;
	
	fputs(mesg, stdout);
	errno = 0;
	if ((val = sysconf(name)) < 0) {
		if (errno != 0) {
			err_sys("sysconf error");
		}
		fputs(" (not defined)\n", stdout);
	} else 
		printf(" %ld\n", val);
}

static void
pr_pathconf(char *mesg, char *path, int name)
{
	long val;
	
	fputs(mesg, stdout);
	
	errno = 0;
	if ((val = pathconf(path, name)) < 0) {
		if (errno != 0) {
			err_sys("pathconf error, path = %s", path);
		}
		fputs(" (no limit)\n", stderr);
	} else {
		printf(" %ld\n", val);
	}
}
